<?php

include('header.php');
include('bottom_banners.php');
include('chat.php');
include('sidebar_banners.php');


$tip_galerije = empty($_GET['tip_galerije']) ? 'colour' : $_GET['tip_galerije'];

if ($_GET['tip_galerije'] == 'custom') {
    $kljucne = " ";
    $opis = " ";
    $naziv = " ";
    $kljucne_reci = mres(($_GET['gal_filter_term']));
    $sortiranje = mres(($_GET['gal_filter_sort']));
    $kljucne_reci = explode(" ", $kljucne_reci);
   
    $ukupno_kljucne_reci = count($kljucne_reci);
    for ($i = 0; $i < $ukupno_kljucne_reci; $i++) {
        if ($i == ($ukupno_kljucne_reci-1)) {
            $kljucne.=" kljucne_reci like '%$kljucne_reci[$i]%'";
            $opis.=" opis like '%$kljucne_reci[$i]%'";
            $naziv.=" naziv like '%$kljucne_reci[$i]%'";
        } else {
            $kljucne.=" kljucne_reci like '%$kljucne_reci[$i]%' or ";
            $opis.=" opis like '%$kljucne_reci[$i]%' or ";
            $naziv.=" naziv like '%$kljucne_reci[$i]%' or ";
        }
    }

    $totalGallery = getTotalSearchResult($kljucne, $opis, $naziv);
    $paginatorGallery = new Paginator;
    $paginatorGallery->items_total = $totalGallery;
    $paginatorGallery->mid_range = 5;
    $paginatorGallery->paginate();
    $GalleryPhotos = searchPhotos($kljucne, $opis, $naziv, $sortiranje, $paginatorGallery->limit);
    $smarty->assign('paginationGallery', $paginatorGallery->display_pages());
    $smarty->assign('GalleryPhotos', $GalleryPhotos);
} else {
    $totalGallery = getTotalGallery($tip_galerije);
    $paginatorGallery = new Paginator;
    $paginatorGallery->items_total = $totalGallery;
    $paginatorGallery->mid_range = 5;
    $paginatorGallery->paginate();
    $GalleryPhotos = getGalleryPhotos($tip_galerije, $paginatorGallery->limit);
    $smarty->assign('paginationGallery', $paginatorGallery->display_pages());
    $smarty->assign('GalleryPhotos', $GalleryPhotos);
}



$smarty->assign('media', siteinfo('media'));

$smarty->assign('tip_galerije', $tip_galerije);

$smarty->display('galerija.tpl');
include('footer.php');
?>
